package com.sdp.wx.flow;

import org.flowable.engine.delegate.TaskListener;
import org.flowable.task.service.delegate.DelegateTask;
import org.springframework.util.StringUtils;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.sdp.core.bizc.utils.ApplicationContextUtils;
import com.sdp.wx.db.wx_assets_enable.entity.WxAssetsEnable;
import com.sdp.wx.db.wx_assets_enable.service.IWxAssetsEnableService;
import com.sdp.wx.db.wx_assets_info.entity.WxAssetsInfo;
import com.sdp.wx.db.wx_assets_info.service.IWxAssetsInfoService;
import com.sdp.wx.utils.WxConstants;

public class AssetsEnableEndNodeTaskListener implements TaskListener {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public void notify(DelegateTask delegateTask) {
		String isPass = (String) delegateTask.getVariable("isPass");
		WxAssetsEnable report = (WxAssetsEnable) delegateTask.getVariable("flowData");
		if (!StringUtils.isEmpty(isPass) && WxConstants.是.getCode().equals(isPass)
				&& report != null) {
			IWxAssetsEnableService assetsEnableService = ApplicationContextUtils.getBean(IWxAssetsEnableService.class);
			UpdateWrapper<WxAssetsEnable> updateWrapper = new UpdateWrapper<>();
			updateWrapper.lambda().eq(WxAssetsEnable::getKeyId, report.getKeyId())
				.set(WxAssetsEnable::getApproveStatus, WxConstants.流程审批状态_审批通过.getCode());
			assetsEnableService.update(updateWrapper);
			
			IWxAssetsInfoService assetsInfoService = ApplicationContextUtils.getBean(IWxAssetsInfoService.class);
			UpdateWrapper<WxAssetsInfo> updateWrapperAssets = new UpdateWrapper<>();
			updateWrapperAssets.lambda().eq(WxAssetsInfo::getAssetNo, report.getAssetNo())
				.set(WxAssetsInfo::getUseDate, report.getUseDate())
				.set(WxAssetsInfo::getUseStatus, WxConstants.是.getCode());
			assetsInfoService.update(updateWrapperAssets);
		}
		
		
	}

}
